<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------

namespace Api\Controller;
use Think\Controller\RestController;

/**
 * api请求接口
 * 
 */
class LoginoutController extends RestController {
	
    protected function _initialize()
    {
        $path="./Runtime/Logs/Api/api_".date('Ymd').".log";        
        $data=array($_REQUEST,$_FILES);   
        $logMsg=json_encode($data);
        error_log($logMsg.PHP_EOL,3,$path);
    }
	
	/**
	 *app、wap同时登录
	 * 提交参数方式	post
	 * member 用户id
	 */
	 public function loginSynchro(){
	     //$memberId=90;
	     $memberId=I('post.memberId','','string');
	     $memberName=I('post.userName','','string');
	     $password=I('post.mallSign','','string');
	     $postData['memberId']=$memberId;
	     $postData['username']=$memberName;
	     $postData['password']=$password;
	     if(!$memberId){
	         $this->ajaxReturn(errorReturn('参数有误'));
	     }
	     //$url="http://www.shop.wttai.com/"
	     $url=C('MALL_DOMAIN')."/api/index.php?c=goods&a=Applogin";
	    
	     $res=curl_post($url,$postData);
	     $res=json_decode($res,true);

	     $data['cookie']='key='.$res['datas']['key'];
	     if($res['code']==200){
	         setcookie('key',$res['datas']['key'],0,'/','.wttai.com');
	        
	         $this->ajaxReturn(successReturn($data));

	     }else{
	         $this->ajaxReturn(errorReturn($res['datas']['error']));       
	     }
    
	 }
	 /**
	  *app、wap同时退出
	  * 提交参数方式	post
	  * member 用户id
	  */
	 public function Applogout(){

	     $memberId=I('post.memberId','','string');
	     $postData['member_id']=$memberId;
	     if(!$memberId){
	         $this->ajaxReturn(errorReturn('参数有误'));
	     }
	     $url=C('MALL_DOMAIN')."/api/index.php?c=goods&a=Applogout";
	     $res=curl_post($url,$postData);
	     $res=json_decode($res,true);
	     if($res['code']==200){
	         if($_COOKIE['key']){
	            setcookie('key','',time()-3600, '/','.wttai.com');
	         }
	         $this->ajaxReturn(successReturn());
	     }else{
	         $this->ajaxReturn(errorReturn($res['datas']['error']));
	     }
	 
	 }
	
}
